local hx__chuangshiji = fk.CreateSkill {
  name = "hx__chuangshiji",
  tags = { Skill.Limited , Skill.Compulsory},
  dynamic_desc = function(self, player)
    if player:getMark("hx__chuangshiji-change") > 0 then
      return "hx__chuangshiji2"
    else
      return "hx__chuangshiji"
    end
  end,
}


hx__chuangshiji:addEffect('active', {
  name = "hx__chuangshiji",
  card_num = 0,
  target_num = 0,
  prompt = "#hx__chuangshiji",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    for _, tar in ipairs(room.alive_players) do
      room:setBanner("@[:]hx__chuangshiji-change", "hx__chuangshiji-change")
      room:addPlayerMark(tar, "hx__chuangshiji-change", 1)
    end
    if player:hasSkill("hx__diwangshi",true) then
      room:handleAddLoseSkills(player, "-hx__diwangshi")
    end
  end,
})

hx__chuangshiji:addEffect(fk.EventPhaseChanging, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__chuangshiji.name,true, true) and data.phase and target:getMark("hx__chuangshiji-change") > 0
  end,
  on_use = function(self, event, target, player, data)
    if data.phase == Player.Draw then
      data.phase = Player.Play
    elseif data.phase == Player.Play then
      data.phase = Player.Draw
    end
  end,
})

hx__chuangshiji:addEffect(fk.AfterCardsMove, {
  anim_type = "offensive",
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(hx__chuangshiji.name) and player:getMark("hx__chuangshiji-change") > 0 then
      for _, move in ipairs(data) do
        if move.to ~= player and move.toArea == Card.PlayerHand then
          if not move.to:isNude() and not move.to.dead and move.to:getHandcardNum() > player:getHandcardNum() then
            return true
          end
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player.room:doAnimate("InvokeSkill", {
      name = "hx__chuangshiji",
      player = player.id,
      skill_type = "offensive",
    })
    for _, move in ipairs(data) do
      if move.to and move.to ~= player and move.toArea == Card.PlayerHand and move.moveInfo and #move.moveInfo > 0 then
        local target = move.to
        if target and not target.dead then
          local x = target:getHandcardNum() - player:getHandcardNum()
          local all_cards = {}
          for _, area in ipairs({Player.Hand}) do
            table.insertTable(all_cards, target:getCardIds(area))
          end
          if #all_cards > 0 and x > 0 then
            local cards = room:askToChooseCards(player, {
              target = target,
              min = 0,
              max = x,
              flag = "h",
              skill_name = hx__chuangshiji.name,
              prompt = "请选择该角色的至多"..x.."张手牌弃置",
            })
            if #cards > 0 then
              room:throwCard(cards, hx__chuangshiji.name, target, player)
              for _, id in ipairs(cards) do
                local card = Fk:getCardById(id)
                if card.trueName == "slash" then
                  room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove,hx__chuangshiji.name, "", true, player,{"@@hx__chuangshiji-inhand",1})
                end
              end
            end
          end
        end
      end
    end
  end,
})


hx__chuangshiji:addEffect("targetmod", {
  name = "hx__shandianti",
  bypass_distances = function(self, player, skill, card)
    return player:hasSkill(hx__chuangshiji.name,true) and card:getMark("@@hx__chuangshiji-inhand") > 0 and card
  end,
  bypass_times = function(self, player, skill, scope, card)
    return player:hasSkill(hx__chuangshiji.name,true) and card:getMark("@@hx__chuangshiji-inhand") > 0 and card
  end,

})


return hx__chuangshiji